#include <sys_config.h>
#include <basic_types.h>
#include <mediatypes.h>
#include <api/libc/alloc.h>
#include <api/libc/printf.h>
#include <api/libc/string.h>
#include <osal/osal.h>
#include <hld/hld_dev.h>
#include <hld/dsc/dsc.h>

#ifdef DSC_DEBUG
#define DSC_DEBUG_PRINTF  libc_printf
#else
#define DSC_DEBUG_PRINTF(...) do{}while(0)
#endif


void des_open(pDES_DEV pDesDev )
{
    if(pDesDev == NULL)
       return ;
       
    if(pDesDev->open)
    {
        pDesDev->open(pDesDev);
    }

    return ;
}



void des_close(pDES_DEV pDesDev)
{
    if(pDesDev == NULL)
       return;
       
    if (pDesDev->close)
    {
        pDesDev->close(pDesDev);
    }

    return ;
}



RET_CODE des_decrypt_cts(pDES_DEV pDesDev,UINT16 dmx_id,  UINT8 *input, UINT8 *output, UINT32 total_length,UINT8 *residue)
{
   RET_CODE ret =  RET_FAILURE ;

   if(pDesDev == NULL)
       return ret;
       
   if (pDesDev->Decrypt_cts)
   {
     ret = pDesDev->Decrypt_cts( pDesDev, dmx_id,  input, output, total_length,residue);
   }
   return ret;
}

RET_CODE des_decrypt(pDES_DEV pDesDev,UINT16 dmx_id,  UINT8 *input, UINT8 *output, UINT32 total_length)
{
   RET_CODE ret =  RET_FAILURE ;

   if(pDesDev == NULL)
       return ret;
       
   if (pDesDev->Decrypt)
   {
     ret = pDesDev->Decrypt( pDesDev, dmx_id,  input, output, total_length);
   }

   return ret;
}



RET_CODE des_encrypt(pDES_DEV pDesDev,UINT16 dmx_id,  UINT8 *input, UINT8 *output, UINT32 total_length)
{
   RET_CODE ret =  RET_FAILURE ;

   if(pDesDev == NULL)
       return ret;
       
   if (pDesDev->Encrypt)
   {
     ret = pDesDev->Encrypt( pDesDev, dmx_id,  input, output, total_length);
   }

   return ret;
}



RET_CODE des_ioctl( pDES_DEV pDesDev ,UINT32 cmd , UINT32 param)
{
    RET_CODE ret =  RET_FAILURE ;

    DSC_DEBUG_PRINTF("des_ioctl %x %x %x\n", pDesDev , cmd ,  param);

   if(pDesDev == NULL)
       return ret;
       
   if (pDesDev->Ioctl)
   {
     ret = pDesDev->Ioctl(  pDesDev , cmd ,  param);
   }
    return ret;  
}



/*----------------------------------------*/
void aes_open(pAES_DEV pAesDev )
{
    if(pAesDev == NULL)
       return ;
       
    if (pAesDev->open)
    {
        pAesDev->open(pAesDev);
    }

    return ;
}


void aes_close(pAES_DEV pAesDev)
{
    if(pAesDev == NULL)
       return ;
       
    if (pAesDev->close)
    {
        pAesDev->close(pAesDev);
    }

    return ;
}

RET_CODE aes_decrypt_cts(pAES_DEV pAesDev,UINT16 dmx_id,  UINT8 *input, UINT8 *output, UINT32 total_length,UINT8 *residue)
{
   RET_CODE ret =  RET_FAILURE ;

   if(pAesDev == NULL)
       return ret;
       
   if (pAesDev->Decrypt_cts)
   {
     ret = pAesDev->Decrypt_cts( pAesDev, dmx_id,  input, output, total_length,residue);
   }

   return ret;
}
RET_CODE aes_decrypt(pAES_DEV pAesDev,UINT16 dmx_id,  UINT8 *input, UINT8 *output, UINT32 total_length)
{
   RET_CODE ret =  RET_FAILURE ;

   if(pAesDev == NULL)
       return ret;
       
   if (pAesDev->Decrypt)
   {
     ret = pAesDev->Decrypt( pAesDev, dmx_id,  input, output, total_length);
   }

   return ret;
}
RET_CODE aes_encrypt(pAES_DEV pAesDev,UINT16 dmx_id,  UINT8 *input, UINT8 *output, UINT32 total_length)
{
   RET_CODE ret =  RET_FAILURE ;

    if(pAesDev == NULL)
       return ret;
       
   if (pAesDev->Encrypt)
   {
     ret = pAesDev->Encrypt( pAesDev, dmx_id,  input, output, total_length);
   }

   return ret;
}



RET_CODE aes_ioctl( pAES_DEV pAesDev ,UINT32 cmd , UINT32 param)
{
   RET_CODE ret =  RET_FAILURE ;

   DSC_DEBUG_PRINTF("aes_ioctl %x %x %x\n", pAesDev , cmd ,  param);

   if(pAesDev == NULL)
       return ret;

   if (pAesDev->Ioctl)
   {
     ret = pAesDev->Ioctl(  pAesDev , cmd ,  param);
   }
    return ret;  
}
/*********************************************/



void csa_open(pCSA_DEV pCsaDev)
{
   if(pCsaDev == NULL)
       return ;
       
   if(pCsaDev->open)
   {
      pCsaDev->open(pCsaDev);
   }

   return ;
}



void csa_close(pCSA_DEV pCsaDev)
{
   if(pCsaDev == NULL)
       return ;
       
   if(pCsaDev->close)
   {
      pCsaDev->close(pCsaDev);
   }

   return ;
}


RET_CODE csa_decrypt(pCSA_DEV pCsaDev,UINT16 dmx_id,  UINT8 *input, UINT8 *output, UINT32 total_length)
{
   RET_CODE ret =  RET_FAILURE ;

   if(pCsaDev == NULL)
       return ret;
       
   if (pCsaDev->Decrypt)
   {
     ret = pCsaDev->Decrypt( pCsaDev, dmx_id,  input, output, total_length);
   }

   return ret;
}



RET_CODE csa_ioctl( pCSA_DEV pCsaDev ,UINT32 cmd , UINT32 param)
{
   RET_CODE ret =  RET_FAILURE ;

   DSC_DEBUG_PRINTF("csa_ioctl %x %x %x\n", pCsaDev , cmd ,  param);

   if(pCsaDev == NULL)
       return ret;
       
   if (pCsaDev->Ioctl)
   {
     ret = pCsaDev->Ioctl(  pCsaDev , cmd ,  param);
   }
    return ret;  
}


void sha_open(pSHA_DEV pShaDev)
{
   if(pShaDev == NULL)
       return ;
   if(pShaDev->open)
   {
      pShaDev->open(pShaDev);
   }

   return ;
}


void sha_close(pSHA_DEV pShaDev)
{
    if(pShaDev == NULL)
       return ;
   if(pShaDev->close)
   {
      pShaDev->close(pShaDev);
   }

   return ;
}


RET_CODE sha_ioctl( pSHA_DEV pShaDev ,UINT32 cmd , UINT32 param)
{
   RET_CODE ret =  RET_FAILURE ;

    DSC_DEBUG_PRINTF("sha_ioctl %x %x %x\n", pShaDev , cmd ,  param);

   if(pShaDev == NULL)
     return ret;
   
   if(pShaDev->Ioctl)
   {
     ret = pShaDev->Ioctl(pShaDev , cmd ,  param);
   }
    return ret;  
}

RET_CODE sha_digest(pSHA_DEV pShaDev, UINT8 *input, UINT8 *output,UINT32 data_length)
{
  RET_CODE ret =  RET_FAILURE ;
  DSC_DEBUG_PRINTF("%x,%x,%x,%x\n",pShaDev, input, output, data_length);
  
    if(pShaDev == NULL)
       return ret ;

     if(pShaDev->digest)
     {
        ret = pShaDev->digest( pShaDev, input, output,data_length);
     }

     return ret ;
}

RET_CODE dsc_ioctl( pDSC_DEV pDscDev,UINT32 cmd , UINT32 param)
{
   RET_CODE ret =  RET_FAILURE ;

   //DSC_DEBUG_PRINTF("dsc_ioctl %x %x %x\n", pDscDev , cmd ,  param);

   if(pDscDev == NULL)
     return ret;
   
   if(pDscDev->ioctl)
   {
     ret = pDscDev->ioctl(pDscDev , cmd ,  param);
   }
    return ret;  
}

